using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WiMo.Games.Drawables;
using Microsoft.Xna.Framework.Graphics;

namespace WiMo.Games.Display.WP7S.XNA.Drawables
{
    public class SpriteImage : SpriteImageBase
    {
        public override void Load(IContentManager contentManager, string name)
        {
            var texture = contentManager.GetTexture(name);

            TextureList.Add(texture);

            CollisionDetectionPoints.Clear();

            if (CollisionShape == CollisionShapes.Sphere)
            {
                var rads = 2.0f * Math.PI / 8.0f;
                var radius = Size.Width / 2;

                for (var idx = 0.0f; idx < 8f; ++idx)
                    CollisionDetectionPoints.Add(new Location(Math.Sin(rads * idx) * radius, Math.Cos(rads * idx) * radius));
            }
        }

        public ITexture Texture
        {
            get { return TextureList[ImageIndex]; }
        }

        public override Size Size
        {
            get
            {
                var texture = Texture.TextureInformation as Texture2D;

                return new Size(texture.Width * Scale.X, texture.Height * Scale.Y);
            }
            set { throw new Exception("Setting size of bitmap not supported."); }
        }

        public override Size UnscaledSize
        {
            get
            {
                return new Size((int)(Size.Width / Scale.X), (int)(Size.Height / Scale.Y));
            }
            set { throw new Exception("Setting size of bitmap not supported."); }
        }

        public override int AddImage(IContentManager contentManager, string name)
        {
            TextureList.Add(contentManager.GetTexture(name));

            return TextureList.Count;
        }

        public override void Render(IDisplay display)
        {
            display.Render(this);
        }
    }
}